package com.yf1706.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yf1706.bean.CountAbsenceDeduct;
import com.yf1706.bean.CountIncomeTaxRate;
import com.yf1706.bean.CountOvertimeSalaryRate;
import com.yf1706.bean.Emp;
import com.yf1706.dao.jpa.IBaseSalaryJDAO;
import com.yf1706.dao.jpa.ICheckMonthReportJDAO;
import com.yf1706.dao.jpa.ICountAbsenceDeductDAO;
import com.yf1706.dao.jpa.ICountIncomeTaxRateJDAO;
import com.yf1706.dao.jpa.ICountOvertimeSalaryRateJDAO;
import com.yf1706.dao.jpa.IEmpJDAO;
import com.yf1706.dao.jpa.IFloatSalaryJDAO;
import com.yf1706.dao.jpa.SocialSecurityJDAO;
import com.yf1706.vo.CheckMonthReportVO;
import com.yf1706.vo.CountBaseSalaryVO;
import com.yf1706.vo.CountFloatSalaryVO;
import com.yf1706.vo.CountSocialSecurityVO;

/**
 * 计算工资服务
 * 
 * @author 锦涛
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CountSalaryService {

	@Autowired
	private IBaseSalaryJDAO baseSalaryJDAO; // 本薪

	@Autowired
	private SocialSecurityJDAO SecurityJDAO; // 社保

	@Autowired
	private IFloatSalaryJDAO floatSalaryJDAO; // 浮动工资

	@Autowired
	private ICheckMonthReportJDAO checkReportJDAO; // 考勤数据
	
	@Autowired
	private ICountAbsenceDeductDAO countAbsenceDeductDAO;  //缺勤扣款规则
	
	@Autowired
	private ICountOvertimeSalaryRateJDAO OvertimeRateJDAO; //加班规则
	
	@Autowired
	private ICountIncomeTaxRateJDAO taxRateJDAO;  // 个人所得税税率
	
	@Autowired
	private IEmpJDAO empJDAO; //员工
	
	/**
	 * 根据ID查找员工
	 */
	public Emp findEmpByID(int id) {
		return empJDAO.findByEmpId(id);
	}

	/**
	 * 根据时间和账套ID得到本薪值
	 */
	public List<CountBaseSalaryVO> findBSBySidAndDate(int sId, Date countDate) {
		return baseSalaryJDAO.findSearchBySidAndDate(sId, countDate);
	}

	/**
	 * 根据时间和账套ID得到社保值
	 */
	public List<CountSocialSecurityVO> findSSBySidAndDate(int sId, Date countDate) {
		return SecurityJDAO.findSearchBySidAndDate(sId, countDate);
	}

	/**
	 * 根据时间得到考勤数据
	 */
	public List<CheckMonthReportVO> findCRByDate(Date countDate) {
		return checkReportJDAO.queryAllBySmonth(countDate);
	}
	
	/**
	 * 获得缺勤计算规则
	 */
	public List<CountAbsenceDeduct> queryAbsenceDeductAll(){
		return countAbsenceDeductDAO.findAll();
	}

	/**
	 * 获得加班计算规则
	 */
	public List<CountOvertimeSalaryRate> queryOvertimeRateAll() {
		return OvertimeRateJDAO.findAll();
	}
	
	/**
	 * 根据时间和账套ID得到浮动工资值
	 */
	public List<CountFloatSalaryVO> findFSBySidAndDate(int sId, Date countDate) {
		return floatSalaryJDAO.findSearchBySidAndDate(sId, countDate);
	}
	
	/**
	 * 获得个税税率表
	 */
	public List<CountIncomeTaxRate> queryTaxAll(){
		return taxRateJDAO.findAll();
	}
}
